<template>
  <div id="app" @mouseover="changeLastTime">
    <!-- <img src="./assets/logo.png"> -->
    <router-view />
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      lastActTime: new Date().getTime(),
      timeOut: 30 * 60 * 1000
    };
  },
  created() {
    let _this = this;

    _this.tTime();

    var utoken = localStorage.getItem("USER_TOKEN");
    console.log("token", utoken);

    if (utoken != null) {
      utoken = utoken.replace('"', "");
      utoken = utoken.replace('"', "");
      console.log(utoken);

      this.$http.get(`index/validToken?token=${utoken}`).then(res => {
        console.log("index/validToken?token=:", res);
        if (res.data) {
          console.log("mmmmmmm");
        } else {
          console.log("tttttgggggggg");
          localStorage.clear();
        }
      });
    }
  },
  mounted() {
    window.setInterval(this.tTime, 30 * 1000);
  },

  methods: {
    changeLastTime() {
      let path = this.$route.path;
      // if (whiteList.indexOf(path) !== -1) {
      //   // console.log(22)
      //   return
      // }
      // console.log(11)
      this.lastActTime = new Date().getTime();

      localStorage.setItem("lastActTime", this.lastActTime);
    },

    // logout () {
    //   console.log("gggggggg");

    //   localStorage.clear()
    //   // location.reload()
    // },
    tTime() {
      let path = this.$route.path;
      // if (whiteList.indexOf(path) !== -1) {
      //   return
      // }
      let ctTime = new Date().getTime();
      let lastActTime = localStorage.getItem("lastActTime");
      if (!lastActTime) {
        lastActTime = this.lastActTime;
      }
      let that = this;
      if (ctTime - lastActTime > that.timeOut) {
        console.log("gggggg");

        localStorage.clear();

        // this.$get(`logout/${that.$db.get('USER').userId}`).then(() => {
        //   return new Promise((resolve, reject) => {
        //     loginExpireAction()
        //   })
        // }).catch(() => {
        //   this.$message.error('退出系统失败')
        // })
      }
    }
  }
};
</script>
